/*
 * MrtdDataContainer.java
 *
 * Created on 26. September 2007
 *
 *  This file is part of JSmex.
 *
 *  JSmex is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  JSmex is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package jsmex.function;

import java.util.Date;

/**
 *
 * @author Tobias Senger
 */
public class MrtdDataContainer {
    
    private String name;
    private String surname;
    private String dateOfBirth; 
    private Date doB;
    private String nationality;
    private String sex;
    private String dateOfExpiry;
    private Date doE;
    private String docNumber;
    private String docType;
    private String issuer;
    private String optData;
    
    
    public MrtdDataContainer(String mrz) {
        this(mrz.substring(0,44), mrz.substring(44,88));     
    }
    
    
    /** Creates a new instance of MrtdDataContainer */
    public MrtdDataContainer(String mrz1, String mrz2) {
        
        System.out.println("MRZ1: "+mrz1+"\nMRZ2: "+mrz2);
        
        this.docType = mrz1.substring(0,2).replace('<', ' ').trim();
        this.issuer = mrz1.substring(2,5);
        
        String helpName =mrz1.substring(5,44);
        for (int i = 0;i<helpName.length();i++) {
            if (helpName.charAt(i)=='<' && helpName.charAt(i+1)=='<') {
                this.surname = helpName.substring(0,i).replace('<', ' ').trim();
                this.name = helpName.substring(i+2).replace('<', ' ').trim();
                break;
            }
        }
        
        
        this.docNumber = mrz2.substring(0,9).replace('<', ' ').trim(); 
        this.nationality = mrz2.substring(10,13);
        this.dateOfBirth = mrz2.substring(13,19);
        this.sex = mrz2.substring(20,21);
        this.dateOfExpiry = mrz2.substring(21,27);
        this.optData = mrz2.substring(28,42).replace('<', ' ').trim();
        
    }
    
    public String getName() {
        return name;
    }
    
    public String getSurname() {
        return surname;
    }
    
    public String getDateOfBirth() {
        return dateOfBirth;
    }
    
    public String getNationality() {
        return nationality;
    }
    
    public String getSex() {
        return sex;
    }
    
    public String getDateOfExpiry() {
        return dateOfExpiry;
    }
    
    public String getDocNumber() {
        return docNumber;
    }
    
    public String getIssuer() {
        return issuer;
    }
    
    public String getOptData() {
        return optData;
    }
    
    public String getDocType() {
        return docType;
    }
}
